package hotel.compare.oversea.service.impl;

import hotel.base.oversea.constant.CommonUrlConstants;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.utils.JacksonUtil;
import hotel.base.oversea.utils.RestTemplateUtils;
import hotel.base.oversea.utils.Result;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsStatusDetailBaseCallbackVo;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsStatusDetailCallbackVo;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsCallbackVo;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsPriceBaseDetailVo;
import hotel.compare.oversea.config.service.RedisService;
import hotel.compare.oversea.entity.meituan.MtHotelGoods;
import hotel.compare.oversea.mapper.meituan.MtHotelGoodsMapper;
import hotel.compare.oversea.service.MeituanSpiderService;
import hotel.compare.oversea.vo.meituan.MtHotelGoodsResultVO;
import hotel.compare.oversea.vo.meituan.MtHotelPriceModelVO;
import hotel.compare.oversea.vo.meituan.MtHotelRoomVO;
import hotel.compare.oversea.vo.meituan.MtHotelVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.util.*;
import java.util.concurrent.*;


/**
 * 爬取美团酒店记录
 *
 * @author Zhang·JZ
 * @date 2020-09-22
 */
@Slf4j
@Service
public class MeituanSpiderServiceImpl extends BaseServiceImpl implements MeituanSpiderService {

    @Autowired
    private MtHotelGoodsMapper mtHotelGoodsMapper;

    @Autowired
    private RedisService redisService;

    @Autowired
    private RestTemplate restTemplate;

    //统计当前爬取条数
    private String loadKey = "spider_meituan_load_num_key";


    //统计当前爬取百分比
    private String loadPer = "spider_meituan_load_per_key";


    //已爬取条数
    private int spiderCount = 0;
    //需要爬取总数
    private int totalCount = 0;


    private CloseableHttpClient httpClient = null;
    private CloseableHttpResponse response = null;
    // 创建httpGet远程连接实例
    private HttpGet httpGet = null;

    //爬虫相关url 地址
    private String hotelUrl = "https://mf.meituan.com/#/hotel/poi/detail";//爬取酒店地址  https://mf.meituan.com/#/hotel/poi/detail?poiId=350403&roomNum=1&startDay=20200921&endDay=20200922


    //爬虫美团具体下单前校验相关url 地址
    private String hotelGoodsUrl = "https://mf.meituan.com/fenxiao-web/hotel/order/prebook";//爬取酒店地址  https://mf.meituan.com/#/hotel/deal/index?goodsId=67102711&goodsType=1&poiId=350403&roomNum=1&startDay=20200922&endDay=20200923


    //开始日期
    private String startDate;

    //结束日期
    private String endDate;

    //推送房态变更
    private String hhbRoomStateNoticeUrl = CommonUrlConstants.CALLBACK_HOST+"/mtHotelOrderNotify/hhbRoomStateNotice";

    //推送价格变更
    private String hhbGoodsPriceNoticeUrl = CommonUrlConstants.CALLBACK_HOST+"/mtHotelOrderNotify/hhbGoodsPriceNotice";

    private String cookie;//JSESSIONID=node01hknoqjk1hx3x26v570tae9na860875.node0; _lxsdk_cuid=17278dc633fc8-04e7e564812aa2-6373664-1fa400-17278dc633fc8; ci=62; iuuid=AFD13B9A1E82B29623986C539ED7B14D790CBF6EF25785B8B8282129B48091FA; cityname=%E5%8E%A6%E9%97%A8; _lxsdk=AFD13B9A1E82B29623986C539ED7B14D790CBF6EF25785B8B8282129B48091FA; Hm_lvt_f66b37722f586a240d4621318a5a6ebe=1595483024; __utma=211559370.1262968389.1595483024.1595483024.1595483024.1; __utmz=211559370.1595483024.1.1.utmcsr=baidu|utmccn=baidu|utmcmd=organic|utmcct=zt_search; i_extend=C085021465567978133866654328195751632659_g1E_c3_e13940464909580632571_a%e6%b9%be%e6%82%a6%e5%9f%8e_b400203_o1_dhotelpoitagb_k1001_f192659289Gempty__xhotelhomepage__yselect__zhour; IJSESSIONID=193w3q54ys0tz1hr89t2z4udsx; _ga=GA1.2.1262968389.1595483024; uuid=e06f25933ece4d11b968.1600413326.1.0.0; mtcdn=K; userTicket=IxkLkGdSXtROdHRlSfuqIHwyHhwVbowRbSsHtWnq; u=219845832; n=zhangjz918; lt=DkJ43oS8RkmX0HY8AjSveWkhgk4AAAAAkAsAABeF3GuwKcauaMYQlRWH1_ihQfhyMThAyVvPD35dL6SFEecybEy9FMbrXt2RbrlqDQ; mt_c_token=DkJ43oS8RkmX0HY8AjSveWkhgk4AAAAAkAsAABeF3GuwKcauaMYQlRWH1_ihQfhyMThAyVvPD35dL6SFEecybEy9FMbrXt2RbrlqDQ; token=DkJ43oS8RkmX0HY8AjSveWkhgk4AAAAAkAsAABeF3GuwKcauaMYQlRWH1_ihQfhyMThAyVvPD35dL6SFEecybEy9FMbrXt2RbrlqDQ; lsu=; token2=DkJ43oS8RkmX0HY8AjSveWkhgk4AAAAAkAsAABeF3GuwKcauaMYQlRWH1_ihQfhyMThAyVvPD35dL6SFEecybEy9FMbrXt2RbrlqDQ; isid=2BC0392767D49633E70F118C29AE0C5E; logintype=normal; oops=DkJ43oS8RkmX0HY8AjSveWkhgk4AAAAAkAsAABeF3GuwKcauaMYQlRWH1_ihQfhyMThAyVvPD35dL6SFEecybEy9FMbrXt2RbrlqDQ; unc=zhangjz918; firstTime=1600413391781; _lx_utm=utm_source%3Dbaidu%26utm_campaign%3Dbaidu%26utm_medium%3Dorganic%26utm_content%3Dzt_search; bzacctid=69333241; ssoLogin=HHB1688; fxUserId=22082; fxUserName=HHB1688; dtorId=12350; bsid=SXkV9X9pN49Eirq4SSZ1qG1yIaIXO8sFjZqnjZWYZw4eBnxvS_F3iVtNw8bwG9VxXIyU5tNA9FGp15feDrvFmg; __mta=216308393.1598634255513.1600754482133.1600754490725.170; _lxsdk_s=174b466efc7-4a5-a3c-330%7C%7C5


    //开启或者关闭 0：关；1：开
    private String openMtSpiderKey = "open_meituan_spider_hotel_key";

    /**
     * 美团爬取酒店公共方法
     * @param url
     * @return html
     */
    public String spiderCommon(String url){
        String retHtml = "";
        // 通过址默认配置创建一个httpClient实例
        httpClient = HttpClients.createDefault();
        httpGet = new HttpGet(url);
        // 传输的类型
        httpGet.addHeader("cookie", cookie);
        httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36");
        httpGet.addHeader("referer", "https://mf.meituan.com/");
        try {
            // 设置配置请求参数
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000)// 连接主机服务超时时间
                    .setConnectionRequestTimeout(35000)// 请求超时时间
                    .setSocketTimeout(60000)// 数据读取超时时间
                    .build();
            // 为httpGet实例设置配置
            httpGet.setConfig(requestConfig);
            // 执行get请求得到返回对象
            response = httpClient.execute(httpGet);
            // 通过返回对象获取返回数据
            HttpEntity entity = response.getEntity();
            // 通过EntityUtils中的toString方法将结果转换为字符串
            retHtml = EntityUtils.toString(entity);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭资源
            if (null != response) {
                try {
                    response.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (null != httpClient) {
                try {
                    httpClient.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return retHtml;
    }


    /**
     * 爬取美团后台房态、房价相关信息
     * @param poiIdList 美团酒店id
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @Override
    public boolean meituanSpiderHotel(List<String> poiIdList,String cookies) throws ExecutionException, InterruptedException {
        cookie = cookies;

        startDate = DateUtil.formatDate(new Date(),"yyyyMMdd");
        endDate = DateUtil.formatDate(DateUtil.getNextDays(1),"yyyyMMdd");



        //开始时间
        long start = System.currentTimeMillis();

        StringBuffer ret = new StringBuffer();
        // 总数
        int dataSize = poiIdList.size();
        totalCount = dataSize;
        // 线程数
        int threadNum = 50;
        //大于10万，则用20个线程
        if(dataSize>100000){
            threadNum=100;
        }else if(dataSize<50){
            threadNum=dataSize;
        }

        // 每500条数据开启一条线程
        int num = 0;
        if((dataSize%threadNum) > 0){
            num = 1;
        }
        int threadSize = dataSize/threadNum + num;
        // 定义标记,过滤threadNum为整数
        boolean special = dataSize % threadSize == 0;

        // 创建一个线程池
        ExecutorService exec = Executors.newFixedThreadPool(threadNum);
        // 定义一个任务集合
        List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
        Callable<Integer> task = null;
        List<String> cutList = new ArrayList<>();

        //如果数量小直接执行
        if(dataSize<= threadNum){
            final String taskNum = String.valueOf(1);
            task = new Callable<Integer>() {
                @Override
                public Integer call() throws Exception {

                    Thread.sleep(10);
                    checkSpiderHotel(taskNum,poiIdList);
                    return 1;
                }
            };
            // 这里提交的任务容器列表和返回的Future列表存在顺序对应的关系
            tasks.add(task);
        }else {
            // 确定每条线程的数据
            for (int i = 0; i < threadNum; i++) {
                if (i == threadNum - 1) {
                    if (special) {
                        break;
                    }
                    cutList = poiIdList.subList(threadSize * i, dataSize);
                } else {
                    cutList = poiIdList.subList(threadSize * i, threadSize * (i + 1));
                }
                final List<String> listStr = cutList;
                final String taskNum = String.valueOf(i + 1);
//            final List<CompareHotel> listStr = compareHotelList; //开启单线程
                task = new Callable<Integer>() {

                    @Override
                    public Integer call() throws Exception {

                        Thread.sleep(10);
                        checkSpiderHotel(taskNum,poiIdList);
                        return 1;
                    }
                };
                // 这里提交的任务容器列表和返回的Future列表存在顺序对应的关系
                tasks.add(task);
            }
        }

        List<Future<Integer>> results = exec.invokeAll(tasks);

        for (Future<Integer> future : results) {
            log.info("future.get()>>>" + future.get().toString());
            ret.append(future.get());
        }

        // 关闭线程池
        exec.shutdown();
        log.info("线程任务执行结束");
        long end = System.currentTimeMillis();
        log.info("爬虫时长为：{}",(end-start));
        return true;
    }

    /**
     * 调用爬虫方法并做解析
     * @param taskNum
     * @param poiIdList
     */
    public void checkSpiderHotel(String taskNum,List<String> poiIdList){
        if(!ObjectUtils.isEmpty(poiIdList) && poiIdList.size()>0){
            String nowDate = DateUtil.formatDate(startDate,"yyyy-MM-dd");
            poiIdList.forEach(poiId -> {

                //价格变更
                List<MtHotelGoodsCallbackVo> goods = new ArrayList<>();
                //房态变更
                List<MtHotelGoodsStatusDetailCallbackVo> rsList = new ArrayList<>();

                //拼接url地址
                String url = hotelUrl + "?poiId="+poiId+"&roomNum=1&startDay="+startDate+"&endDay="+endDate;
                String retHtml = spiderCommon(url);
                //将返回结果格式化
                Map<String,Object> retMap = JacksonUtil.parse(retHtml,Map.class);
                MtHotelVO mtHotelVo = JacksonUtil.objToBean(retMap.get("data"), MtHotelVO.class);
                if(!ObjectUtils.isEmpty(mtHotelVo)){
                    List<MtHotelRoomVO> mtHotelRoomVoList = mtHotelVo.getHotelGoodsInfoVOList();
                    log.info("mtHotelRoomVoList>>>>>>>>{}",mtHotelRoomVoList);
                    if(!mtHotelRoomVoList.isEmpty() && mtHotelRoomVoList.size()>0){
                        mtHotelRoomVoList.forEach(mtHotelRoomVo->{
                            //mtHotelId ,mtGoodsId, mtDate(yyyy-MM-dd), mtSalePrice
                            String hotelId = String.valueOf(mtHotelRoomVo.getPoiId());
                            String goodsId = String.valueOf(mtHotelRoomVo.getGoodsId());
                            String roomName = String.valueOf(mtHotelRoomVo.getRoomName());
                            String salePrice = mtHotelRoomVo.getMtPrice();//美团售卖价格
                            String fenxiaoPrice = mtHotelRoomVo.getFenxiaoPrice();//分销价格
                            int goodsStatus = mtHotelRoomVo.getGoodsStatus();//房态 0：满房； 1：有房

                            //判断如果是满房直接调用通知
                            if(goodsStatus == 0){
                                MtHotelGoodsStatusDetailCallbackVo mtHotelGoodsStatusDetailCallbackVo = new MtHotelGoodsStatusDetailCallbackVo();
                                mtHotelGoodsStatusDetailCallbackVo.setHotelId(Integer.valueOf(hotelId));
                                mtHotelGoodsStatusDetailCallbackVo.setGoodsId(Integer.valueOf(goodsId));

                                List<MtHotelGoodsStatusDetailBaseCallbackVo> goodsStatuses = new ArrayList<>();
                                if(true){
                                    MtHotelGoodsStatusDetailBaseCallbackVo mtHotelGoodsStatusDetailBaseCallbackVo = new MtHotelGoodsStatusDetailBaseCallbackVo();
                                    mtHotelGoodsStatusDetailBaseCallbackVo.setStatus(0);
                                    mtHotelGoodsStatusDetailBaseCallbackVo.setDate(nowDate);

                                    goodsStatuses.add(mtHotelGoodsStatusDetailBaseCallbackVo);
                                }

                                mtHotelGoodsStatusDetailCallbackVo.setGoodsStatuses(goodsStatuses);
                                rsList.add(mtHotelGoodsStatusDetailCallbackVo);

                            }


                            Map queMap = new HashMap();
                            queMap.put("mtHotelId",hotelId);
                            queMap.put("mtGoodsId",goodsId);
                            queMap.put("mtDate",nowDate);
                            queMap.put("mtSalePrice",salePrice);

                            int hasCount = mtHotelGoodsMapper.queryGoodsByDate(queMap);
                            //如果不存在记录，则说明价格有变动；推送给美团通知携程修改价格
                            if(hasCount == 0){
                                MtHotelGoodsCallbackVo mtHotelGoodsCallbackVo = new MtHotelGoodsCallbackVo();
                                mtHotelGoodsCallbackVo.setHotelId(hotelId);
                                mtHotelGoodsCallbackVo.setGoodsId(goodsId);
                                mtHotelGoodsCallbackVo.setGoodsName(roomName);//爬取数据中没有产品名称，用roomName 代替

                                List<MtHotelGoodsPriceBaseDetailVo> priceModels = new ArrayList<>();
                                if(true){
                                    MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo = new MtHotelGoodsPriceBaseDetailVo();
                                    mtHotelGoodsPriceBaseDetailVo.setDate(nowDate);
                                    mtHotelGoodsPriceBaseDetailVo.setSalePrice(Integer.valueOf(salePrice));
                                    int subPrice = Integer.valueOf(salePrice)-Integer.valueOf(fenxiaoPrice);
                                    mtHotelGoodsPriceBaseDetailVo.setSubPrice(subPrice);
                                    mtHotelGoodsPriceBaseDetailVo.setDayType(0);//默认0 ：平日
                                    priceModels.add(mtHotelGoodsPriceBaseDetailVo);

                                }

                                mtHotelGoodsCallbackVo.setPriceModels(priceModels);
                                goods.add(mtHotelGoodsCallbackVo);

                            }

                        });
                    }
                }


                //调用房态变更
                RestTemplateUtils.post(hhbRoomStateNoticeUrl,JacksonUtil.objectToJson(rsList),restTemplate);

                //调用房价变更
                RestTemplateUtils.post(hhbGoodsPriceNoticeUrl,JacksonUtil.objectToJson(goods),restTemplate);
            });
        }
    }


    /**
     * 爬取美团后台下单前校验
     * @param mtHotelGoodsList 美团酒店id
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @Override
    public boolean meituanSpiderHotelGoods(List<MtHotelGoods> mtHotelGoodsList,String cookies) throws ExecutionException, InterruptedException {
        cookie = cookies;
        startDate = DateUtil.formatDate(new Date(),"yyyyMMdd");
        endDate = DateUtil.formatDate(DateUtil.getNextDays(1),"yyyyMMdd");

        Date date = new Date();
        int hours = date.getHours();//获取当前小时 24小时制
        //如果是凌晨5点前，抓取昨天数据
        if(hours<=6){
            startDate = DateUtil.formatDate(DateUtil.getNextDays(-1),"yyyyMMdd");
            endDate = DateUtil.formatDate(new Date(),"yyyyMMdd");
        }

        //开始时间
        long start = System.currentTimeMillis();

        StringBuffer ret = new StringBuffer();
        // 总数
        int dataSize = mtHotelGoodsList.size();
        totalCount = dataSize;
        // 线程数
        int threadNum = 50;
        //大于10万，则用20个线程
        if(dataSize>10000){
            threadNum=100;
        }else if(dataSize<50){
            threadNum=dataSize;
        }

        // 每500条数据开启一条线程
        int num = 0;
        if((dataSize%threadNum) > 0){
            num = 1;
        }
        int threadSize = dataSize/threadNum + num;
        // 定义标记,过滤threadNum为整数
        boolean special = dataSize % threadSize == 0;

        // 创建一个线程池
        ExecutorService exec = Executors.newFixedThreadPool(threadNum);
        // 定义一个任务集合
        List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
        Callable<Integer> task = null;
        List<MtHotelGoods> cutList = new ArrayList<>();

        //如果数量小直接执行
        if(dataSize<= threadNum){
            final String taskNum = String.valueOf(1);
            task = new Callable<Integer>() {
                @Override
                public Integer call() throws Exception {

                    Thread.sleep(10);
                    checkSpiderHotelGoods(taskNum,mtHotelGoodsList);
                    return 1;
                }
            };
            // 这里提交的任务容器列表和返回的Future列表存在顺序对应的关系
            tasks.add(task);
        }else {
            // 确定每条线程的数据
            for (int i = 0; i < threadNum; i++) {
                if (i == threadNum - 1) {
                    if (special) {
                        break;
                    }
                    cutList = mtHotelGoodsList.subList(threadSize * i, dataSize);
                } else {
                    cutList = mtHotelGoodsList.subList(threadSize * i, threadSize * (i + 1));
                }
                final List<MtHotelGoods> listStr = cutList;
                final String taskNum = String.valueOf(i + 1);
//            final List<CompareHotel> listStr = compareHotelList; //开启单线程
                task = new Callable<Integer>() {

                    @Override
                    public Integer call() throws Exception {

                        Thread.sleep(10);
                        checkSpiderHotelGoods(taskNum,mtHotelGoodsList);
                        return 1;
                    }
                };
                // 这里提交的任务容器列表和返回的Future列表存在顺序对应的关系
                tasks.add(task);
            }
        }

        List<Future<Integer>> results = exec.invokeAll(tasks);

//        for (Future<Integer> future : results) {
//            log.info("future.get()>>>" + future.get().toString());
//            ret.append(future.get());
//        }

        // 关闭线程池
        exec.shutdown();
        //爬取完成移除当前开关redis
        redisService.remove(openMtSpiderKey);
        log.info("线程任务执行结束");
        long end = System.currentTimeMillis();
        log.info("爬虫时长为：{}",(end-start));
        return true;
    }


    /**
     * 调用爬虫方法并做解析，下单前校验
     * @param taskNum
     * @param mtHotelGoodsList
     */
    public void checkSpiderHotelGoods(String taskNum,List<MtHotelGoods> mtHotelGoodsList){
        if(!ObjectUtils.isEmpty(mtHotelGoodsList) && mtHotelGoodsList.size()>0){
            String nowDate = DateUtil.formatDate(startDate,"yyyy-MM-dd");
            mtHotelGoodsList.forEach(mtHotelGoods -> {
                if(redisService.exists(openMtSpiderKey)){
                    //如果是关闭则不往下执行
                    if("0".equals(String.valueOf(redisService.get(openMtSpiderKey)))){
                        return;
                    }
                }
                //价格变更
                List<MtHotelGoodsCallbackVo> goods = new ArrayList<>();
                //房态变更
                List<MtHotelGoodsStatusDetailCallbackVo> rsList = new ArrayList<>();

                //拼接url地址
                String url = hotelGoodsUrl+"?goodsId="+mtHotelGoods.getMtGoodsId()+"&goodsType=1&poiId="+mtHotelGoods.getMtHotelId()+"&roomNum=1&startDay="+startDate+"&endDay="+endDate;
                String retHtml = spiderCommon(url);
                log.info("hotelGoodsUrl>>>>>{}",url);
                log.info("retHtml>>>>>{}",retHtml);
                //将返回结果格式化
                Map<String,Object> retMap = JacksonUtil.parse(retHtml,Map.class);
                MtHotelGoodsResultVO mtHotelGoodsResultVO = JacksonUtil.objToBean(retMap.get("data"), MtHotelGoodsResultVO.class);
                if(Integer.valueOf(retMap.get("status").toString()) == 0 && !ObjectUtils.isEmpty(mtHotelGoodsResultVO)){
                    String hotelId = String.valueOf(mtHotelGoodsResultVO.getPoiId());
                    String goodsId = String.valueOf(mtHotelGoodsResultVO.getGoodsId());
                    String roomName = String.valueOf(mtHotelGoodsResultVO.getRoomName());
                    int salePrice = mtHotelGoodsResultVO.getMtTotalPrice();//美团售卖价格
                    int fenxiaoPrice = mtHotelGoodsResultVO.getFenxiaoTotalPrice();//分销价格

                    List<MtHotelPriceModelVO> mtHotelPriceModelVOList = mtHotelGoodsResultVO.getHotelPriceModelVOList();
                    log.info("mtHotelRoomVoList>>>>>>>>{}",mtHotelPriceModelVOList);
                    if(!mtHotelPriceModelVOList.isEmpty() && mtHotelPriceModelVOList.size()>0){
                        mtHotelPriceModelVOList.forEach(mtHotelPriceModelVO->{

                            Map queMap = new HashMap();
                            queMap.put("mtHotelId",hotelId);
                            queMap.put("mtGoodsId",goodsId);
                            queMap.put("mtDate",nowDate);
                            queMap.put("mtSalePrice",String.valueOf(salePrice));

                            int hasCount = mtHotelGoodsMapper.queryGoodsByDate(queMap);
                            //如果不存在记录，则说明价格有变动；推送给美团通知携程修改价格
                            if(hasCount == 0){
                                MtHotelGoodsCallbackVo mtHotelGoodsCallbackVo = new MtHotelGoodsCallbackVo();
                                mtHotelGoodsCallbackVo.setHotelId(hotelId);
                                mtHotelGoodsCallbackVo.setGoodsId(goodsId);
                                mtHotelGoodsCallbackVo.setGoodsName(roomName);//爬取数据中没有产品名称，用roomName 代替

                                List<MtHotelGoodsPriceBaseDetailVo> priceModels = new ArrayList<>();
                                if(true){
                                    MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo = new MtHotelGoodsPriceBaseDetailVo();
                                    mtHotelGoodsPriceBaseDetailVo.setDate(nowDate);
                                    mtHotelGoodsPriceBaseDetailVo.setSalePrice(Integer.valueOf(salePrice));
                                    int subPrice = Integer.valueOf(salePrice)-Integer.valueOf(fenxiaoPrice);
                                    mtHotelGoodsPriceBaseDetailVo.setSubPrice(subPrice);
                                    mtHotelGoodsPriceBaseDetailVo.setDayType(0);//默认0 ：平日
                                    priceModels.add(mtHotelGoodsPriceBaseDetailVo);

                                }

                                mtHotelGoodsCallbackVo.setPriceModels(priceModels);
                                goods.add(mtHotelGoodsCallbackVo);

                            }

                        });
                    }
                }else{//对象为空则直接为满房直接调用通知
                    MtHotelGoodsStatusDetailCallbackVo mtHotelGoodsStatusDetailCallbackVo = new MtHotelGoodsStatusDetailCallbackVo();
                    mtHotelGoodsStatusDetailCallbackVo.setHotelId(Integer.valueOf(mtHotelGoods.getMtHotelId()));
                    mtHotelGoodsStatusDetailCallbackVo.setGoodsId(Integer.valueOf(mtHotelGoods.getMtGoodsId()));

                    List<MtHotelGoodsStatusDetailBaseCallbackVo> goodsStatuses = new ArrayList<>();
                    if(true){
                        MtHotelGoodsStatusDetailBaseCallbackVo mtHotelGoodsStatusDetailBaseCallbackVo = new MtHotelGoodsStatusDetailBaseCallbackVo();
                        mtHotelGoodsStatusDetailBaseCallbackVo.setStatus(0);
                        mtHotelGoodsStatusDetailBaseCallbackVo.setDate(nowDate);

                        goodsStatuses.add(mtHotelGoodsStatusDetailBaseCallbackVo);
                    }

                    mtHotelGoodsStatusDetailCallbackVo.setGoodsStatuses(goodsStatuses);
                    rsList.add(mtHotelGoodsStatusDetailCallbackVo);
                }


                //调用房态变更
                if(!rsList.isEmpty() && rsList.size()>0){
                    Map statusMap = new HashMap();
                    statusMap.put("rsList",rsList);
                    log.info("hhbRoomStateNoticeUrl>>>{};JacksonUtil.objectToJson(statusMap)>>>{}",hhbRoomStateNoticeUrl,JacksonUtil.objectToJson(statusMap));
                    Result resultState = RestTemplateUtils.post(hhbRoomStateNoticeUrl,JacksonUtil.objectToJson(statusMap),restTemplate);
                    log.info("resultState>>>>{}",resultState);
                }

                //调用房价变更
                if(!goods.isEmpty() && goods.size()>0) {
                    Map goodsMap = new HashMap();
                    goodsMap.put("goods", goods);
                    log.info("hhbGoodsPriceNoticeUrl>>>{};JacksonUtil.objectToJson(goodsMap)>>>{}",hhbGoodsPriceNoticeUrl,JacksonUtil.objectToJson(goodsMap));
                    Result resultPrice = RestTemplateUtils.post(hhbGoodsPriceNoticeUrl, JacksonUtil.objectToJson(goodsMap), restTemplate);
                    log.info("resultPrice>>>>{}",resultPrice);
                }
            });
        }
    }


}
